<?php
namespace Admin\Model;

use Think\Model;

class AttendModel extends Model {


    public function getAttendByTid($tid) {

        if (empty($tid)) return null;

        $result = $this->table("__ATTEND__ attend, __STUDENT__ student, __TIMETABLE__ timetable")
                       ->field("attend.id ,student.student_id , student.name AS student_name, timetable.week,timetable.xq,timetable.start,timetable.end")
                       ->where("attend.teachplan_id = {$tid} AND attend.student_id = student.id AND attend.timetable_id = timetable.id ")
                       ->select();
        
		if (empty($result)) return null;
        return $result;

    }

    /**
     * 获取日出勤统计
     * @param  integer $y      年
     * @param  integer $m      月
     * @param  integer $d      日
     * @param  integer $status 出勤状态
     * @return integer         返回日出勤数量
     */
    public function getDayAttend($y,$m,$d,$status) {
      
      $start = "{$y}-{$m}-{$d} 06:00:00";
      $end = "{$y}-{$m}-{$d} 22:00:00";

      $count = $this->where("status = {$status} AND addtime > '{$start}' AND addtime < '{$end}'")
                    ->count();
      return (int)$count;
    }


}